package housing.task1.actor;

import housing.task1.generator.AutoCompleter;

import javax.xml.bind.annotation.*;
import java.util.Random;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Address", propOrder = {
        "_street",
        "_houseNumber",
        "_flatNumber"

})
public class Address {
    private static long static_id;

    @XmlElement(required = true)
    private String _street;
    private int _houseNumber;
    private int _flatNumber;
    @XmlAttribute(name = "_address_id", required = true)
    private long _address_id;

    @Deprecated
    public static Address randomAddress() {
        long id;
        Random random = new Random();
        id = random.nextInt(10) + 50;

        String street = AutoCompleter.Address.generateStreet();
        int houseNumber = AutoCompleter.Address.generateHouseNumber();
        int flatNumber = AutoCompleter.Address.generateFlatNumber();

        return new Address(id, street, houseNumber, flatNumber);
    }

    public void setRandomAddress() {
        long id;
        Random random = new Random();
        id = random.nextInt(10) + 50;

        String street = AutoCompleter.Address.generateStreet();
        int houseNumber = AutoCompleter.Address.generateHouseNumber();
        int flatNumber = AutoCompleter.Address.generateFlatNumber();

        set_address_id(id);
        set_street(street);
        set_houseNumber(houseNumber);
        set_flatNumber(flatNumber);
    }


    public Address() {
        setRandomAddress();
    }

    public Address(long id, String street, int houseNumber, int flatNumber) {
        this._address_id = id;
        this._street = street;
        this._houseNumber = houseNumber;
        this._flatNumber = flatNumber;
    }


    private void assignId() {
        ++static_id;
        this.set_address_id(static_id);
    }


    @Override
    public String toString() {
        return this.get_address_id() + " " +
               this._street + "-" +
               this._houseNumber + "/" +
               this._flatNumber;
    }


    public long get_address_id() {
        return _address_id;
    }

    public void set_address_id(long _address_id) {
        this._address_id = _address_id;
    }

    public String get_street() {
        return _street;
    }

    public void set_street(String _street) {
        this._street = _street;
    }

    public int get_houseNumber() {
        return _houseNumber;
    }

    public void set_houseNumber(int _houseNumber) {
        this._houseNumber = _houseNumber;
    }

    public int get_flatNumber() {
        return _flatNumber;
    }

    public void set_flatNumber(int _flatNumber) {
        this._flatNumber = _flatNumber;
    }

}   //class Address}